package com.web.dao;

import com.web.controller.web.WebStoreController;
import com.web.entity.StoreApply;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @author FDjavaone
 */
public class StoreApplySqlProvider {


    public String insertSelective(StoreApply record) {
        BEGIN();
        INSERT_INTO("t_store_apply");

        if (record.getmId() != null) {
            VALUES("m_id", "#{mId,jdbcType=BIGINT}");
        }

        if (record.getType() != null) {
            VALUES("type", "#{type,jdbcType=VARCHAR}");
        }

        if (record.getMerchantName() != null) {
            VALUES("merchant_name", "#{merchantName,jdbcType=VARCHAR}");
        }

        if (record.getLevel() != null) {
            VALUES("level", "#{level,jdbcType=VARCHAR}");
        }

        if (record.getLogo() != null) {
            VALUES("logo", "#{logo,jdbcType=VARCHAR}");
        }

        if (record.getLicenceNo() != null) {
            VALUES("licence_no", "#{licenceNo,jdbcType=VARCHAR}");
        }

        if (record.getLicenceImg() != null) {
            VALUES("licence_img", "#{licenceImg,jdbcType=VARCHAR}");
        }

        if (record.getIdentityAImg() != null) {
            VALUES("identity_a_img", "#{identityAImg,jdbcType=VARCHAR}");
        }

        if (record.getIdentityBImg() != null) {
            VALUES("identity_b_img", "#{identityBImg,jdbcType=VARCHAR}");
        }

        if (record.getStoreImg() != null) {
            VALUES("store_img", "#{storeImg,jdbcType=VARCHAR}");
        }

        if (record.getContactor() != null) {
            VALUES("contactor", "#{contactor,jdbcType=VARCHAR}");
        }

        if (record.getContactPhone() != null) {
            VALUES("contact_phone", "#{contactPhone,jdbcType=VARCHAR}");
        }

        if (record.getContactTel() != null) {
            VALUES("contact_tel", "#{contactTel,jdbcType=VARCHAR}");
        }

        if (record.getProvince() != null) {
            VALUES("province", "#{province,jdbcType=VARCHAR}");
        }

        if (record.getCity() != null) {
            VALUES("city", "#{city,jdbcType=VARCHAR}");
        }

        if (record.getRegion() != null) {
            VALUES("region", "#{region,jdbcType=VARCHAR}");
        }

        if (record.getStreet() != null) {
            VALUES("street", "#{street,jdbcType=VARCHAR}");
        }

        if (record.getAddress() != null) {
            VALUES("address", "#{address,jdbcType=VARCHAR}");
        }

        if (record.getLoc() != null) {
            VALUES("loc", "#{loc,jdbcType=VARCHAR}");
        }

        if (record.getReason() != null) {
            VALUES("reason", "#{reason,jdbcType=VARCHAR}");
        }
        if (record.getStatus() != null) {
            VALUES("status", "#{status,jdbcType=INTEGER}");
        }
        if (record.getStatus() != null) {
            VALUES("storeType", "#{storeType,jdbcType=VARCHAR}");
        }


        if (record.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            VALUES("modify_time", "#{modifyTime,jdbcType=TIMESTAMP}");
        }

        return SQL();
    }


    public String updateByPrimaryKeySelective(StoreApply record) {
        BEGIN();
        UPDATE("t_store_apply");

        if (record.getmId() != null) {
            SET("m_id = #{mId,jdbcType=BIGINT}");
        }

        if (record.getType() != null) {
            SET("type = #{type,jdbcType=VARCHAR}");
        }

        if (record.getMerchantName() != null) {
            SET("merchant_name = #{merchantName,jdbcType=VARCHAR}");
        }

        if (record.getLevel() != null) {
            SET("level = #{level,jdbcType=VARCHAR}");
        }

        if (record.getLogo() != null) {
            SET("logo = #{logo,jdbcType=VARCHAR}");
        }

        if (record.getLicenceNo() != null) {
            SET("licence_no = #{licenceNo,jdbcType=VARCHAR}");
        }

        if (record.getLicenceImg() != null) {
            SET("licence_img = #{licenceImg,jdbcType=VARCHAR}");
        }

        if (record.getIdentityAImg() != null) {
            SET("identity_a_img = #{identityAImg,jdbcType=VARCHAR}");
        }

        if (record.getIdentityBImg() != null) {
            SET("identity_b_img = #{identityBImg,jdbcType=VARCHAR}");
        }

        if (record.getStoreImg() != null) {
            SET("store_img = #{storeImg,jdbcType=VARCHAR}");
        }

        if (record.getContactor() != null) {
            SET("contactor = #{contactor,jdbcType=VARCHAR}");
        }

        if (record.getContactPhone() != null) {
            SET("contact_phone = #{contactPhone,jdbcType=VARCHAR}");
        }

        if (record.getContactTel() != null) {
            SET("contact_tel = #{contactTel,jdbcType=VARCHAR}");
        }

        if (record.getProvince() != null) {
            SET("province = #{province,jdbcType=VARCHAR}");
        }

        if (record.getCity() != null) {
            SET("city = #{city,jdbcType=VARCHAR}");
        }

        if (record.getRegion() != null) {
            SET("region = #{region,jdbcType=VARCHAR}");
        }

        if (record.getStreet() != null) {
            SET("street = #{street,jdbcType=VARCHAR}");
        }

        if (record.getAddress() != null) {
            SET("address = #{address,jdbcType=VARCHAR}");
        }

        if (record.getLoc() != null) {
            SET("loc = #{loc,jdbcType=VARCHAR}");
        }

        if (record.getReason() != null) {
            SET("reason = #{reason,jdbcType=VARCHAR}");
        }

        if (record.getStatus() != null) {
            SET("status = #{status,jdbcType=INTEGER}");
        }

        if (record.getStoreType() != null) {
            SET("storeType = #{storeType,jdbcType=VARCHAR}");
        }
        if (record.getCreateTime() != null) {
            SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            SET("modify_time = #{modifyTime,jdbcType=TIMESTAMP}");
        }

        WHERE("id = #{id,jdbcType=BIGINT}");

        return SQL();
    }


    public String selectAllStoreApply(WebStoreController.StoreApplyColumns record) {
        BEGIN();
        SELECT("id");
        SELECT("m_id");
        SELECT("type");
        SELECT("merchant_name");
        SELECT("level");
        SELECT("logo");
        SELECT("licence_no");
        SELECT("licence_img");
        SELECT("identity_a_img");
        SELECT("identity_b_img");
        SELECT("store_img");
        SELECT("contactor");
        SELECT("contact_phone");
        SELECT("contact_tel");
        SELECT("province");
        SELECT("city");
        SELECT("region");
        SELECT("street");
        SELECT("address");
        SELECT("loc");
        SELECT("reason");
        SELECT("status");
        SELECT("storeType");
        SELECT("create_time");
        SELECT("modify_time");
        FROM("t_store_apply");

        if (record.getType() != null && !"".equals(record.getType())) {
            WHERE("type = #{type,jdbcType=VARCHAR}");
        }

        if (record.getMerchantName() != null && !"".equals(record.getMerchantName())) {
            WHERE("merchant_name = #{merchantName,jdbcType=VARCHAR}");
        }

        if (record.getLevel() != null && !"".equals(record.getLevel())) {
            WHERE("level = #{level,jdbcType=VARCHAR}");
        }

        if (record.getLicenceNo() != null && !"".equals(record.getLicenceNo())) {
            WHERE("licence_no = #{licenceNo,jdbcType=VARCHAR}");
        }

        if (record.getContactor() != null && !"".equals(record.getContactor())) {
            WHERE("contactor = #{contactor,jdbcType=VARCHAR}");
        }

        if (record.getContactPhone() != null && !"".equals(record.getContactPhone())) {
            WHERE("contact_phone = #{contactPhone,jdbcType=VARCHAR}");
        }

        if (record.getContactTel() != null && !"".equals(record.getContactTel())) {
            WHERE("contact_tel = #{contactTel,jdbcType=VARCHAR}");
        }

        if (record.getStatus() != null && !"".equals(record.getStatus())) {
            WHERE("status = #{status,jdbcType=INTEGER}");
        }
        if (record.getStoreType() != null && !"".equals(record.getStoreType())) {
            WHERE("storeType = #{storeType,jdbcType=VARCHAR}");
        }

        if (record.getProvince() != null && !"".equals(record.getProvince())) {
            WHERE("province = #{province,jdbcType=VARCHAR}");
        }

        if (record.getCity() != null && !"".equals(record.getCity())) {
            WHERE("city = #{city,jdbcType=VARCHAR}");
        }

        if (record.getRegion() != null && !"".equals(record.getRegion())) {
            WHERE("region = #{region,jdbcType=VARCHAR}");
        }

        ORDER_BY("create_time desc");

        return SQL();
    }
}